package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zjr
 * @version 1.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    CustomerDao customerDao;
    @Override
    public Map<String, Object> customerList(Integer page, Integer rows, String customerName) {
        Map<String,Object> map = new HashMap<>();
        List<Customer> list = customerDao.customerList(page-1,rows,customerName);
        map.put("total",list.size());
        map.put("rows",list);
        return map;
    }

    @Override
    public ServiceVO saveCustomer(Customer customer, Integer customerId) {
        if (customerId == null) {
            customerDao.insertCustomer(customer);
        }else {
            customerDao.updateCustomer(customer,customerId);
        }
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    @Override
    public ServiceVO deleteCustomer(String ids) {
        customerDao.deleteCustomer(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
}
